FROM gradle:6.8.0-jdk11 as builder
RUN mkdir -p /home/gradle/cache_home
ENV GRADLE_USER_HOME /home/gradle/cache_home
RUN mkdir -p /usr/src/java-code/controllers/redis-cluster-controller
COPY controllers/redis-cluster-controller/build.gradle /usr/src/java-code/controllers/redis-cluster-controller/
RUN mkdir -p /usr/src/java-code/operators/redis-cluster-operator
COPY operators/redis-cluster-operator/build.gradle /usr/src/java-code/operators/redis-cluster-operator/

COPY build.gradle /usr/src/java-code/
COPY settings.gradle /usr/src/java-code/
COPY gradle.properties /usr/src/java-code/
WORKDIR /usr/src/java-code
RUN gradle -p operators/redis-cluster-operator dependencies -i --stacktrace
RUN gradle -p operators/redis-cluster-operator buildDependents -i --stacktrace
COPY controllers/redis-cluster-controller/src /usr/src/java-code/controllers/redis-cluster-controller/src
COPY operators/redis-cluster-operator/src /usr/src/java-code/operators/redis-cluster-operator/src
RUN gradle -p operators/redis-cluster-operator shadowJar -i --stacktrace

FROM azul/zulu-openjdk-alpine:13.0.3-13.31.11-jre-headless
VOLUME /tmp

RUN mkdir -p /home
COPY --from=builder /usr/src/java-code/operators/redis-cluster-operator/build/libs/redis-cluster-operator-1.0-all.jar /home
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezone
WORKDIR /home
ENV JAVA_OPTS=""
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS  -jar redis-cluster-operator-1.0-all.jar" ]